/**
 * @Author: chensj
 * @Date: 18-11-21 下午9:21
 * @Description:
 * @Title:
 */
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const md5 = require('md5-node');

const app = express();

//配置中间件

app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: true,
    cookie: { secure: false }  /*secure true 表示只有https才能使用*/
}))


app.get('/',function (req,res) {

    if(req.session.userInfo){
        res.send('你好,'+req.session.userInfo+',欢迎回来!')
    }else{
        res.send('未登录');
    }

});

app.get('/login',((req,res) => {
    //设置session
    req.session.userInfo = "zhangsan";
    res.send('登陆成功!');
}))


app.listen(3001,'localhost');
